package c.d.a.a.c;

import com.github.mikephil.charting.data.Entry;
import java.util.ArrayList;
import java.util.List;

/* compiled from: DataSet */
public abstract class e<T extends Entry> extends b<T> {
    public List<T> o = null;
    public float p = -3.4028235E38f;
    public float q = Float.MAX_VALUE;
    public float r = -3.4028235E38f;
    public float s = Float.MAX_VALUE;

    /* compiled from: DataSet */
    public enum a {
        UP,
        DOWN,
        CLOSEST
    }

    public e(List<T> list, String str) {
        super(str);
        this.o = list;
        if (list == null) {
            this.o = new ArrayList();
        }
        List list2 = this.o;
        if (list2 != null && !list2.isEmpty()) {
            this.p = -3.4028235E38f;
            this.q = Float.MAX_VALUE;
            this.r = -3.4028235E38f;
            this.s = Float.MAX_VALUE;
            for (Entry B0 : this.o) {
                B0(B0);
            }
        }
    }

    public void B0(T t) {
        if (t != null) {
            if (t.b() < this.s) {
                this.s = t.b();
            }
            if (t.b() > this.r) {
                this.r = t.b();
            }
            C0(t);
        }
    }

    public void C0(T t) {
        if (t.a() < this.q) {
            this.q = t.a();
        }
        if (t.a() > this.p) {
            this.p = t.a();
        }
    }

    public T D(float f, float f2) {
        return q(f, f2, a.CLOSEST);
    }

    public int D0(float f, float f2, a aVar) {
        List list = this.o;
        if (list == null || list.isEmpty()) {
            return -1;
        }
        int i = 0;
        int size = this.o.size() - 1;
        while (i < size) {
            int i2 = (i + size) / 2;
            float b = ((Entry) this.o.get(i2)).b() - f;
            int i3 = i2 + 1;
            float b2 = ((Entry) this.o.get(i3)).b() - f;
            float abs = Math.abs(b);
            b2 = Math.abs(b2);
            if (b2 >= abs) {
                if (abs >= b2) {
                    double d = (double) b;
                    if (d < 0.0d) {
                        if (d >= 0.0d) {
                        }
                    }
                }
                size = i2;
            }
            i = i3;
        }
        if (size != -1) {
            float b3 = ((Entry) this.o.get(size)).b();
            if (aVar == a.UP) {
                if (b3 < f && size < this.o.size() - 1) {
                    size++;
                }
            } else if (aVar == a.DOWN && b3 > f && size > 0) {
                size--;
            }
            if (!Float.isNaN(f2)) {
                int i4;
                while (size > 0 && ((Entry) this.o.get(size - 1)).b() == b3) {
                    size--;
                }
                f = ((Entry) this.o.get(size)).a();
                loop2:
                while (true) {
                    i4 = size;
                    Entry entry;
                    do {
                        size++;
                        if (size >= this.o.size()) {
                            break loop2;
                        }
                        entry = (Entry) this.o.get(size);
                        if (entry.b() != b3) {
                            break loop2;
                        }
                    } while (Math.abs(entry.a() - f2) >= Math.abs(f - f2));
                    f = f2;
                }
                size = i4;
            }
        }
        return size;
    }

    public void F(float f, float f2) {
        List list = this.o;
        if (list != null && !list.isEmpty()) {
            this.p = -3.4028235E38f;
            this.q = Float.MAX_VALUE;
            int D0 = D0(f2, Float.NaN, a.UP);
            for (int D02 = D0(f, Float.NaN, a.DOWN); D02 <= D0; D02++) {
                C0((Entry) this.o.get(D02));
            }
        }
    }

    public List<T> K(float f) {
        ArrayList arrayList = new ArrayList();
        int size = this.o.size() - 1;
        int i = 0;
        while (i <= size) {
            int i2 = (size + i) / 2;
            Entry entry = (Entry) this.o.get(i2);
            if (f == entry.b()) {
                while (i2 > 0 && ((Entry) this.o.get(i2 - 1)).b() == f) {
                    i2--;
                }
                size = this.o.size();
                while (i2 < size) {
                    Entry entry2 = (Entry) this.o.get(i2);
                    if (entry2.b() != f) {
                        break;
                    }
                    arrayList.add(entry2);
                    i2++;
                }
                return arrayList;
            } else if (f > entry.b()) {
                i = i2 + 1;
            } else {
                size = i2 - 1;
            }
        }
        return arrayList;
    }

    public float P() {
        return this.r;
    }

    public float R() {
        return this.q;
    }

    public int i0() {
        return this.o.size();
    }

    public boolean m(T t) {
        if (t == null) {
            return false;
        }
        List list = this.o;
        if (list == null) {
            list = new ArrayList();
        }
        B0(t);
        return list.add(t);
    }

    public float o() {
        return this.s;
    }

    public T q(float f, float f2, a aVar) {
        int D0 = D0(f, f2, aVar);
        return D0 > -1 ? (Entry) this.o.get(D0) : null;
    }

    public T q0(int i) {
        return (Entry) this.o.get(i);
    }

    public float t() {
        return this.p;
    }

    public String toString() {
        StringBuffer stringBuffer = new StringBuffer();
        StringBuffer stringBuffer2 = new StringBuffer();
        StringBuilder g = c.b.a.a.a.g("DataSet, label: ");
        String str = this.c;
        if (str == null) {
            str = "";
        }
        g.append(str);
        g.append(", entries: ");
        g.append(this.o.size());
        g.append("\n");
        stringBuffer2.append(g.toString());
        stringBuffer.append(stringBuffer2.toString());
        for (int i = 0; i < this.o.size(); i++) {
            g = new StringBuilder();
            g.append(((Entry) this.o.get(i)).toString());
            g.append(" ");
            stringBuffer.append(g.toString());
        }
        return stringBuffer.toString();
    }

    public int w(Entry entry) {
        return this.o.indexOf(entry);
    }
}
